home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-09 | 7.0 KB | 265 lines | [TEXT/MPS ] |
- {
- $Workfile: pLayer.p $
- $Revision: 1.0 $
-
- A hack that uses System 7.1's Text Services Manager to display a floating pallette of scripts,
- QuicKeys, and more.
-
- This file is just a very simple application shell. All of the interesting stuff is in
- pLayerUnit.p.
-
- © 1993 CE Software, Inc. All rights reserved.
-
- WHEN WHO WHAT
-
- •••••
-
- •••••
- }
-
- PROGRAM pLayer;
-
- USES Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf, MacPrint, AppleTalk, AppleEvents,
- GestaltEqu,Folders,Aliases,pLayerUnit; {$R-} {$D+}
-
- CONST
- appleMenu = 1;
- MyFileMenu = 2;
-
- lastMenu = MyFileMenu; { number of menus w/ debug}
-
- VAR myMenus: ARRAY [appleMenu..lastMenu] OF MenuHandle; {Handles to all of the menus}
- theChar: CHAR; {keyboard input goes here}
- doneFlag: BOOLEAN; {set when the user quits the program}
- myEvent: EventRecord; {returned by GetNextEvent}
- watchHdl: CursHandle; {the wait cursor}
- IsForeGround: Boolean; {Are we a foreground app?}
-
- Procedure SetIsForeGround;
- type ip=^integer; ih=^ip;
- var h:ih;
- begin
- IsForeGround:=true;
- h:=pointer(GetResource('SIZE',-1));
- if h<>nil then
- if bitand(h^^,$0400)<>0 then IsForeGround:=false;
- end;
-
- {--------------------------------------------------------------------------
-
- Apple Event handlers
- Just handle the required commands. We don't print, so just open files, open the
- app, and quit.
-
- --------------------------------------------------------------------------}
- FUNCTION GotRequiredParams( theAppleEvent: AppleEvent ): OSErr ; { <aevt> }
- VAR typeCode: DescType ;
- actualSize: Size ;
- err: OSErr ;
- BEGIN
- err := AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr,
- typeWildCard, typeCode, nil, 0, actualSize) ; { nil ok: need only function result }
- IF err = errAEDescNotFound THEN GotRequiredParams := noErr
- ELSE IF err = noErr THEN GotRequiredParams := errAEEventNotHandled
- ELSE GotRequiredParams := err ;
- END ; { GotRequiredParams }
-
-
- Function HandleAEQuit(theAppleEvent,reply:AppleEvent; refcon:longint):OSErr;
- begin
- HandleAEQuit:=GotRequiredParams( theAppleEvent );
- doneflag:=true;
- end;
-
- Function HandleAEOpenApp(theAppleEvent,reply:AppleEvent; refcon:longint):OSErr;
- begin
- HandleAEOpenApp:=GotRequiredParams( theAppleEvent );
- DoOpenApp(IsForeGround);
- end;
-
- Function HandleAEOpenFile(theAppleEvent,reply:AppleEvent; theblock:ptr):OSErr;
- var StuffToDo,EachFile:AEDesc;
- returnedtype:AEKeyword;
- FileSpec:FSSpec;
- waschanged:boolean;
-
- Procedure FailErr(io:OSErr);
- begin
- if io<>NoErr then begin
- HandleAEOpenFile:=io;
- exit(HandleAEOpenFile);
- end;
- end;
- begin
- FailErr(AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,StuffToDo));
- FailErr( GotRequiredParams( theAppleEvent ) ) ;
-
- FailErr(AEGetNthDesc(StuffToDo,1,typeAlias,returnedtype,EachFile));
- FailErr(ResolveAlias(nil,pointer(EachFile.datahandle),FileSpec,waschanged));
- DoOpenFile(FileSpec);
-
- HandleAEOpenFile:=NoErr;
- end;
-
- PROCEDURE InstallAppleEvents ;
- VAR
- aevtErr: OSErr ; theproc:procptr;
- BEGIN
- aevtErr := AEInstallEventHandler( kCoreEventClass, kAEQuitApplication,@HandleAEQuit, 0, false ) ;
- aevtErr := AEInstallEventHandler( kCoreEventClass, kAEOpenApplication,@HandleAEOpenApp, 0, false ) ;
- aevtErr := AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments,@HandleAEOpenFile, 0, false ) ;
- END ;
-
- {--------------------------------------------------------------------------
-
- Setup
- Initialize our managers, Install our AppleEvent handlers, and then init the pallette code.
-
- --------------------------------------------------------------------------}
- PROCEDURE SetUp;
-
- VAR i:integer;
- numfiles:integer;
- templong:longint;
- io:OSErr;
- p:procptr;
-
- Procedure DoNotRun(io:OSErr; s:str255);
- begin
- if io<>NoErr then begin
- if IsForeGround then begin
- paramtext(s,'','','');
- i:=StopAlert(801,nil);
- end
- else debugstr(s);
- ExitToShell;
- end;
- end;
-
-
- BEGIN
-
- SetIsForeGround;
-
- if IsForeGround then begin
- MaxApplZone;
- InitGraf(@thePort); {I need QuickDraw}
- InitFonts;
- InitWindows;
- TEInit;
- InitDialogs(NIL);
-
- watchHdl := GetCursor(4);
- HNoPurge (Pointer(watchHdl));
-
- InitMenus;
- myMenus[appleMenu] := GetMenu(appleMenu);
- AddResMenu(myMenus[1],'DRVR'); { desk accessories }
- myMenus[MyFileMenu] := GetMenu(MyFileMenu);
- ClearmenuBar;
- InsertMenu(myMenus[applemenu],0);
- InsertMenu(myMenus[MyFileMenu],0);
- DrawMenuBar;
-
- end
- else begin
- SetApplLimit(pointer(ord4(GetApplLimit)-32768)); {give an additional 32K to stack}
- MaxApplZone;
- InitGraf(@thePort); {still need QuickDraw}
- end;
-
- doneFlag := FALSE;
-
- {See if we can do AppleEvents}
- io:=Gestalt(gestaltAppleEventsAttr,templong);
- if io=NoErr then if not odd(templong) then io:=-1;
- DoNotRun(io,'Apple Events not installed');
-
- InstallAppleEvents;
-
- DoNotRun(InitLayer,'Unable to initialize our Layer stuff');
-
- END; { of SetUp}
-
- {--------------------------------------------------------------------------
-
- DoCommand
- Handle our File and Apple menus.
-
- --------------------------------------------------------------------------}
- PROCEDURE DoCommand (commandkey: boolean);
- VAR name: str255;
- DeskAccUp : boolean;
- num, theMenu, theItem: integer;
- mresult: longint;
- BEGIN {This handles the actions that are initiated through the Menu Manager}
- If Commandkey then mResult := MenuKey(theChar)
- else mResult := MenuSelect (myEvent.where);
- theMenu := HiWord(mResult); theItem := LoWord(mResult);
- CASE theMenu OF
- appleMenu: begin
- IF theItem = 1 THEN num:=Alert(800,nil)
- ELSE BEGIN
- GetItem(myMenus[appleMenu],theItem,name);
- num := OpenDeskAcc(name);
- END
- END;
- MyFileMenu:
- case TheItem of
- 1:HandleNew;
- 2:HandleOpen;
- 3:HandleSave;
- 5:doneFlag := TRUE; { Quit }
- end;
- END; { of menu case }
- HiliteMenu(0)
- END; { of DoCommand }
-
- {--------------------------------------------------------------------------
-
- MainEventLoop
- Handle our events. We don't do very much, just handle menus, so there's
- not much here.
-
- We also call the pallette code's idle routine here.
-
- --------------------------------------------------------------------------}
- PROCEDURE MainEventLoop;
- var dummy:boolean;
- tempwindow:windowptr;
- io:OSErr;
- BEGIN
- REPEAT
- SetCursor(arrow);
-
- dummy := WaitNextEvent(everyEvent,myEvent,$7FFFFFFF,nil);
-
- CASE myEvent.what OF
- kHighLevelEvent:
- io:=AEProcessAppleEvent( myevent ) ; { <aevt> }
- mouseDown:
- if IsForeGround then
- CASE FindWindow(myEvent.where,tempWindow) OF
- inSysWindow: begin SystemClick(myEvent,tempWindow); end;
- inMenuBar: DoCommand(FALSE);
- END;
-
- keyDown, autoKey:
- if IsForeGround then begin
- theChar := CHR(myEvent.message MOD 256); { Mac characters use 8 bits }
- IF BitAnd(myEvent.modifiers,CmdKey) <> 0 THEN begin
- if dummy then DoCommand(TRUE);
- end;
- END; { of keyDown }
- END; { of event case }
- LayerIdleProc(doneflag);
- UNTIL doneFlag;
- END;
-
- BEGIN { main program }
- SetUp;
- MainEventLoop;
- if IsForeGround then SetCursor (watchHdl^^);
- CloseLayer;
- END.
-